package ihis.core.report;

import ihis.core.db.IHISDatabase;
import ihis.model.GeneralFilter;
import ihis.model.IHISConstants;
import ihis.model.ProjectScheduleRiskReport;
import ihis.model.Report;
import ihis.model.Task;
import ihis.model.TaskFilter;

import java.sql.SQLException;
import java.util.List;

public class ProjectScheduleRiskReportFactory extends ReportFactory {

	/* (non-Javadoc)
	 * @see ihis.core.report.ReportFactory#getReport(ihis.model.GeneralFilter)
	 */
	@Override
	public Report getReport(GeneralFilter filter) {
		ProjectScheduleRiskReport report = new ProjectScheduleRiskReport();
		
		try {
			TaskFilter taskFilter = (TaskFilter) filter;
			taskFilter.setTaskType(IHISConstants.TASK_LIST_RISK);
			taskFilter.setStatus(IHISConstants.PROGRESS_STATUS_IN_PROGRESS);
			taskFilter.setRiskType(IHISConstants.RISK_DELAYED);
			@SuppressWarnings("unchecked")
			List<Task> delayedRiskList = IHISDatabase.getSqlMapClient().queryForList("SelectList.Task.Risk", taskFilter);
			
			if(delayedRiskList != null){
				report.setDelayedRiskList(delayedRiskList);
			}
			
			taskFilter = (TaskFilter) filter;
			taskFilter.setTaskType(IHISConstants.TASK_LIST_RISK);
			taskFilter.setStatus(IHISConstants.PROGRESS_STATUS_IN_PROGRESS);
			taskFilter.setRiskType(IHISConstants.RISK_POTENTIAL);
			@SuppressWarnings("unchecked")
			List<Task> potentialRiskList = IHISDatabase.getSqlMapClient().queryForList("SelectList.Task.Risk", taskFilter);
			
			if(potentialRiskList != null){
				report.setPotentialRiskList(potentialRiskList);
			}
			
			// TODO : 팀별 지연, 포텐설 개수 구하는 로직 구현 필요  
//			taskFilter = (TaskFilter) filter;
//			taskFilter.setTaskType(IHISConstants.TASK_LIST_RISK);
//			taskFilter.setStatus(IHISConstants.PROGRESS_STATUS_IN_PROGRESS);
//			@SuppressWarnings("unchecked")
//			List<TeamRisk> teamRiskList = IHISDatabase.getSqlMapClient().queryForList("SelectList.Task.Risk.GroupByTeam", taskFilter);
//			
//			if(teamRiskList != null){
//				report.setTeamRiskList(teamRiskList);
//			}
			
			report.setTaskFilter((TaskFilter) filter);
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		
		return report;
	}

}
